/*************************************************************************
    > File Name: main.c
    > Author: ma6174
    > Mail: ma6174@163.com 
    > Created Time: 2025年02月08日 星期六 09时18分16秒
 ************************************************************************/

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "hwled.h"


static void led_togg(char* str, int index){
	if(!strcmp(str, "on")){
		led_on(index);
	}

	if(!strcmp(str, "off")){
		led_off(index);
	}
};

static int led_switch(char* str){
	
	if(!strcmp(str, "led1")){

		printf("%s: line = %d, return LED1 # %d\n", __func__, __LINE__, LED1);

		return LED1;
	}
		
	if(!strcmp(str, "led2")){
		
		printf("%s: line = %d, return LED2 # %d\n", __func__, __LINE__, LED2);

		return LED2;
	}
	
	if(!strcmp(str, "led3")){
		printf("%s: line = %d, return LED3 # %d\n", __func__, __LINE__, LED3);

		return LED3;
	}
	
	if(!strcmp(str, "led4")){
		printf("%s: line = %d, return LED4 # %d\n", __func__, __LINE__, LED4);

		return LED4;
	}

	return -1;
}



int main(int argc, char* argv[]){

	if(argc < 3){
		
		printf("用法：./led ledx on/off  x 取值1、 2、 3、 4\n");
		
		return -1;
	}

	
	
	char*name = argv[1];

	char*str = argv[2];

	//printf("name = %s, str = %s\n", name, str);

	led_init();

	int index = led_switch(name);

	if(index >= 0){
		
		led_togg(str, index);
	
		led_t led;

		led_staut(index, &led);
	
		printf("当前是第%d个led灯，状态：%s , 名称：%s\n", led.index+1, led.stauts?"关闭":"打开", led.name);

	} else{
		
		printf("用法：./led ledx on/off , x 取值 1、 2、 3、 4\n");
	
	}

	led_free();


	return 0;
}
